package com.bloveoacom.pay;

import android.app.Activity;
import android.content.Context;

import com.alipay.sdk.app.PayTask;
import com.bloveoacom.base.UserInfoBean;
import com.bloveoacom.exception.ApiException;
import com.bloveoacom.http.HttpMethods;
import com.bloveoacom.http.HttpResult;
import com.bloveoacom.mvp.IView;
import com.bloveoacom.observer.BaseSubscriber2;
import com.bloveoacom.util.GsonUtil;
import com.bloveoacom.util.ToastUtil;
import com.bloveoacom.weichi.R;
import com.bloveoacom.weichi.bean.WXPayBean;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import java.util.Map;

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;


/**
 * author: yjl
 * e-mail: 1271901673@qq.com
 * time  : 2018/9/27
 * desc  :
 */
public class PayUtil {
    public static void wxPay(Context mContext, String response){
//        Intent intent = new Intent(mContext, WXPayEntryActivity.class);
//        mContext.startActivityForResult(intent, REQUEST_CODE_PAY);
        WXPayBean wxPayBean = GsonUtil.GsonToBean(response, WXPayBean.class);
        final IWXAPI msgApi = WXAPIFactory.createWXAPI(mContext, null);
        msgApi.registerApp(PayParameter.WX_APP_ID);
        PayReq request = new PayReq();
        request.appId = wxPayBean.appid;
        request.partnerId = wxPayBean.partnerid;
        request.prepayId = wxPayBean.prepayid;
        request.nonceStr = wxPayBean.noncestr;
        request.timeStamp = wxPayBean.timestamp;
        request.packageValue = wxPayBean.packageX;
        request.sign = wxPayBean.sign;
        boolean sendReq = msgApi.sendReq(request);
        if (!sendReq) {
            if (!msgApi.isWXAppInstalled()) {
                ToastUtil.makeShortText(mContext, mContext.getResources().getString(R.string.please_install_wechat));
            } else if (!msgApi.isWXAppSupportAPI()) {
                ToastUtil.makeShortText(mContext, mContext.getResources().getString(R.string.wechat_client_inavailable));
            } else {
                ToastUtil.makeShortText(mContext, mContext.getResources().getString(R.string.payment_failure));
            }
        }
    }

    public static void aliPay(Activity activity){

    }


    public interface PayResult{
         void ok();
         void err();
    }
}
